package com.specialtreasure.freightdepot.activity;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;

import com.app.core.activity.BaseNewActivity;
import com.app.core.config.BaseConfig;
import com.app.core.config.Constants;
import com.app.core.config.MyApp;
import com.specialtreasure.freightdepot.R;
import com.specialtreasure.freightdepot.model.Login;

/**
 * Created by Administrator on 2017/8/9 0009.
 * 启动页
 */

public class SplashActivity extends BaseNewActivity {
    public static final String TAG = "SplashActivity";


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_splash);
        setData();
    }

    private void setData() {
        //延迟2S跳转
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Login login=(Login)MyApp.getInstance().getaCache().getAsObject(Constants.LOGIN);
                Boolean isAutoLogin= MyApp.getInstance().getSp().getValue(Constants.AUTOLOGIN,false);
                //判断用户是否登陆
                if (login!=null){
                    if (isAutoLogin){
                        intent.setClass(mContext, MainActivity.class);
                    }else {
                        intent.setClass(mContext, LoginActivity.class);
                    }
                }else {
                    intent.setClass(mContext, LoginActivity.class);
                }

                //测试用
//                intent.setClass(mContext, LoginActivity.class);
                startActivity(intent);
                finish();
            }
        }, 1000);

    }

    @Override
    public String getActiviyName() {
        return TAG;
    }
}
